package com.ruoyi.api.controller.deal;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.api.annotation.IgnoreAuth;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.deal.bo.HyDealCategoryQueryBo;
import com.ruoyi.deal.domain.HyDealCategory;
import com.ruoyi.deal.service.IHyDealCategoryService;
import com.ruoyi.deal.vo.HyDealCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分类api接口
 * @author lixin
 * @date 2021-06-29 10:06
 */
@RestController
@RequestMapping("/api/category")
public class ApiCategoryController {

	@Autowired
	private IHyDealCategoryService dealCategoryService;

	/**
	 * 获取分类左边列表
	 */
	@IgnoreAuth
	@GetMapping("/selectLeft")
	public AjaxResult selectLeft() {

		List<HyDealCategory> categories = dealCategoryService.selectLeft();
		return AjaxResult.success(categories);
	}

	/**
	 * 根据父类ID获取子类右边列表
	 */
	@IgnoreAuth
	@GetMapping("/selectRight/{categoryId}")
	public AjaxResult selectRight(@PathVariable("categoryId") Integer categoryId) {

		List<HyDealCategory> categories = dealCategoryService.selectRight(categoryId);
		return AjaxResult.success(categories);
	}


	/**
	 * 获取分类下拉树列表
	 */
	@GetMapping("/treeselect")
	public AjaxResult treeselect() {
		HyDealCategoryQueryBo bo = new HyDealCategoryQueryBo();
		List<HyDealCategoryVo> categoriesVo = dealCategoryService.queryList(bo);
		List<HyDealCategory> categories = BeanUtil.copyToList(categoriesVo, HyDealCategory.class);
		return AjaxResult.success(dealCategoryService.buildCategoryTreeSelect(categories));
	}
}
